import 'model.dart';

class UsbDevice {
  final String identifier;
  final String deviceName;
  final String? manufacturerName;
  final String? productName;
  final String? serialNumber;
  final int vendorId;
  final int productId;
  final int configurationCount;
  final List<UsbConfiguration> configurations;

  UsbDevice({
    required this.identifier,
    required this.deviceName,
    required this.manufacturerName,
    required this.productName,
    required this.serialNumber,
    required this.vendorId,
    required this.productId,
    required this.configurationCount,
    required this.configurations,
  });

  factory UsbDevice.fromMap(Map<dynamic, dynamic> map) {
    return UsbDevice(
      identifier: map['identifier'],
      deviceName: map['deviceName'],
      manufacturerName: map['manufacturerName'],
      productName: map['productName'],
      serialNumber: map['serialNumber'],
      vendorId: map['vendorId'],
      productId: map['productId'],
      configurationCount: map['configurationCount'],
      configurations: (map['configurations'] as List)
          .map((e) => UsbConfiguration.fromMap(e))
          .toList(),
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'identifier': identifier,
      'deviceName': deviceName,
      'manufacturerName': manufacturerName,
      'productName': productName,
      'serialNumber': serialNumber,
      'vendorId': vendorId,
      'productId': productId,
      'configurationCount': configurationCount,
      'configurations': configurations.map((e) => e.toMap()).toList(),
    };
  }

  @override
  String toString() => toMap().toString();
}
